<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">

      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="休息开始时间" prop="startTime">
            <!--<el-input v-model="form.startTime" style="width: 370px;" />-->
            <el-time-picker
              v-model="form.startTime"
              format="HH:mm"
              value-format='HH:mm'
              placeholder="任意时间点" style="width: 370px;">
            </el-time-picker>
          </el-form-item>
          <el-form-item label="休息结束时间" prop="endTime">
            <!--<el-input v-model="form.endTime" style="width: 370px;" />-->
            <el-time-picker
              v-model="form.endTime"
              format="HH:mm"
              value-format='HH:mm'
              placeholder="任意时间点" style="width: 370px;">
            </el-time-picker>
          </el-form-item>
          <el-form-item label="类型" prop="type">
            <el-select v-model="form.type" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.classes_type"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="是否禁用" prop="isDisable">
            <el-radio v-model="form.isDisable" v-for="item in dict.whether" :key="item.id" :label="item.value">{{ item.label }}</el-radio>
          </el-form-item>
          <el-form-item label="是否跨天" prop="isDisable">
            <el-radio v-model="form.isAcross" v-for="item in dict.whether" :key="item.id" :label="item.value">{{ item.label }}</el-radio>
          </el-form-item>
          <el-form-item label="备注说明">
            <el-input v-model="form.remark" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="shiftId" label="班次ID" />
        <el-table-column prop="startTime" label="休息开始时间" />
        <el-table-column prop="endTime" label="休息结束时间" />
        <el-table-column prop="remark" label="备注说明" />
        <el-table-column prop="createBy" label="创建人" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="updateBy" label="更新人" />
        <el-table-column prop="updateTime" label="更新时间" />
        <el-table-column prop="type" label="类型">
          <template slot-scope="scope">
            {{ dict.label.classes_type[scope.row.type] }}
          </template>
        </el-table-column>
        <el-table-column prop="isDisable" label="是否禁用">
          <template slot-scope="scope">
            {{ dict.label.whether[scope.row.isDisable] }}
          </template>
        </el-table-column>
        <el-table-column prop="isDisable" label="是否跨天">
          <template slot-scope="scope">
            {{ dict.label.whether[scope.row.isAcross] }}
          </template>
        </el-table-column>
        <el-table-column v-if="checkPer(['admin','factoryShiftTime:edit','factoryShiftTime:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
  import crudFactoryShiftTime from '@/api/factory/factoryShiftTime'
  import CRUD, { presenter, header, form, crud } from '@crud/crud'
  import rrOperation from '@crud/RR.operation'
  import crudOperation from '@crud/CRUD.operation'
  import udOperation from '@crud/UD.operation'
  import pagination from '@crud/Pagination'

  const defaultForm = { id: null, shiftId: null, startTime: null, endTime: null, remark: null, createBy: null, createTime: null, updateBy: null, updateTime: null, type: null, isDisable: '0', isAcross:'0' }
  export default {
    props: {
      id: {
        type: Number,
      },
    },
    watch: {
      id(value) {
        this.crud.toQuery();
      }
    },
    name: 'FactoryShiftTime',
    components: { pagination, crudOperation, rrOperation, udOperation },
    mixins: [presenter(), header(), form(defaultForm), crud()],
    dicts: ['classes_type', 'whether'],
    cruds() {
      return CRUD({ title: '班次休息时间', url: 'api/factoryShiftTime', idField: 'id', sort: 'id,desc',optShow: {
          add: true,
          edit: false,
          del: true,
          download: false,
          reset: false,
          import: false
        }, crudMethod: { ...crudFactoryShiftTime }})
    },
    data() {
      return {
        permission: {
          add: ['admin', 'factoryShiftTime:add'],
          edit: ['admin', 'factoryShiftTime:edit'],
          del: ['admin', 'factoryShiftTime:del']
        },
        rules: {
          startTime: [
            { required: true, message: '休息开始时间不能为空', trigger: 'blur' }
          ],
          endTime: [
            { required: true, message: '休息结束时间不能为空', trigger: 'blur' }
          ],
          type: [
            { required: true, message: '类型不能为空', trigger: 'blur' }
          ],
          isDisable: [
            { required: true, message: '是否禁用不能为空', trigger: 'blur' }
          ]
        },
        queryTypeOptions: [
          { key: 'shiftId', display_name: '班次ID' },
          { key: 'type', display_name: '类型' },
          { key: 'isDisable', display_name: '是否禁用' }
        ]
      }
    },
    methods: {
      // 钩子：在获取表格数据之前执行，false 则代表不获取数据
      [CRUD.HOOK.beforeRefresh]() {
        return true
      },
      //获取数据之前
      [CRUD.HOOK.beforeRefresh]() {
        this.crud.params.shiftId = this.id;
        return true
      },
      //获取数据之前
      [CRUD.HOOK.beforeSubmit]() {
        this.form.shiftId = this.id;
        return true
      },
    }
  }
</script>

<style scoped>

</style>
